package com.happy.manage.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.happy.common.annotation.Log;
import com.happy.common.core.controller.BaseController;
import com.happy.common.core.domain.AjaxResult;
import com.happy.common.enums.BusinessType;
import com.happy.manage.domain.xvideo;
import com.happy.manage.service.IxvideoService;
import com.happy.common.utils.poi.ExcelUtil;
import com.happy.common.core.page.TableDataInfo;
import com.happy.manage.domain.XvideoWithUser;
/**
 * 视频管理Controller
 * 
 * @author ruoyi
 * @date 2024-11-10
 */
@RestController
@RequestMapping("/manage/xvideo")
public class xvideoController extends BaseController
{
    @Autowired
    private IxvideoService xvideoService;

    /**
     * 查询视频管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:xvideo:list')")
    @GetMapping("/list")
    public TableDataInfo list(xvideo xvideo)
    {
        startPage();
//        List<xvideo> list = xvideoService.selectxvideoList(xvideo);
        List<XvideoWithUser> list = xvideoService.getVideosWithUser(xvideo);
        return getDataTable(list);
    }


    /**
     * 导出视频管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:xvideo:export')")
    @Log(title = "视频管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, xvideo xvideo)
    {
        List<xvideo> list = xvideoService.selectxvideoList(xvideo);
        ExcelUtil<xvideo> util = new ExcelUtil<xvideo>(xvideo.class);
        util.exportExcel(response, list, "视频管理数据");
    }

    /**
     * 获取视频管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:xvideo:query')")
    @GetMapping(value = "/{videoId}")
    public AjaxResult getInfo(@PathVariable("videoId") Long videoId)
    {
        return success(xvideoService.selectxvideoByVideoId(videoId));
    }

    /**
     * 新增视频管理
     */
    @PreAuthorize("@ss.hasPermi('manage:xvideo:add')")
    @Log(title = "视频管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody xvideo xvideo)
    {
        return toAjax(xvideoService.insertxvideo(xvideo));
    }

    /**
     * 修改视频管理
     */
    @PreAuthorize("@ss.hasPermi('manage:xvideo:edit')")
    @Log(title = "视频管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody xvideo xvideo)
    {
        return toAjax(xvideoService.updatexvideo(xvideo));
    }

    /**
     * 删除视频管理
     */
    @PreAuthorize("@ss.hasPermi('manage:xvideo:remove')")
    @Log(title = "视频管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{videoIds}")
    public AjaxResult remove(@PathVariable Long[] videoIds)
    {
        return toAjax(xvideoService.deletexvideoByVideoIds(videoIds));
    }
}
